package com.lyluly.coursemgmt.servicemodule.iService.serviceImpl;

import com.lyluly.coursemgmt.servicemodule.iDao.StudentMapper;
import com.lyluly.coursemgmt.servicemodule.iService.IStudentService;
import com.lyluly.coursemgmt.servicemodule.model.Student;
import com.lyluly.coursemgmt.servicemodule.model.StudentExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper studentMapper;

    public void addStudent(Student student) {
        student.setCreatetime(new Date());
        studentMapper.insert(student);
    }

    public void removeStudent(String sId) {
        studentMapper.deleteByPrimaryKey(sId);
    }

    public void modifyStudent(Student student) {
        studentMapper.updateByPrimaryKeySelective(student);
    }

    public Student findStudentById(String sId) {
        return studentMapper.selectByPrimaryKey(sId);
    }

    public List<Student> findStudentListByName(String sName) {
        StudentExample studentExample = new StudentExample();
        studentExample.or().andSNameEqualTo(sName);
        return studentMapper.selectByExample(studentExample);
    }

    public List<Student> findStudentList() {
        return studentMapper.selectByExample(null);
    }
}
